package com.paipai.controller;

import com.paipai.dao.RoundMapper;
import com.paipai.entity.Round;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/round")
public class RoundController {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Autowired
    StringRedisTemplate redisTemplate;
    @Autowired
    RoundMapper roundMapper;

    //倒计时结束 启动场次 将本场次信息放入队列中
    @RequestMapping("/startRound")
    @ResponseBody
    public String startSale(Round round) {
        //查看一下传进来的round值
        System.out.println(round);
        round.setStarttime(new Date());
        //修改状态拍卖中
        round.setState("2");
        rabbitTemplate.convertAndSend("normalExchange", "normalRoutingKey", round);
        roundMapper.updateByPrimaryKey(round);
        return "ok";
    }

}
